<template>
	<view>
		<!-- 顶部导航栏 -->
		<myheader v-if="showHeader"></myheader>

		<mumu-get-qrcode @success="qrcodeSucess" @error="qrcodeError" :continue="false">
			<template v-slot:error>
				<view>摄像头启动失败</view>
			</template>
		</mumu-get-qrcode>
	</view>
</template>

<script>
	import mumuGetQrcode from '@/components/mumu-getQrcode/mumu-getQrcode.vue'
	export default {
		components: {
			mumuGetQrcode
		},
		data() {
			return {}
		},
		methods: {
			qrcodeSucess(data) {
				alert(data);
				const token = uni.getStorageSync('token')
				uni.request({
					url: "https://bg.jswbgz.com/post/copoun_order:get_copoun_code_info", //仅为示例，并非真实接口地址。
					data: {
						key: data,
						token: token,

					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: 'post',
					success: (res) => {
						uni.hideLoading()
						console.log(res)
						const _res = JSON.stringify(res.data);
						alert(_res)
						if (res.data.success) {

						} else if (reslut.data.msg == "登录已失效，请重新登录") {
							uni.removeStorage({
								key: 'UserList',
								success: function(res) {
									uni.redirectTo({
										url: '../pages/login/login'
									});

									setTimeout(function() {
										uni.showToast({
											title: "登录已过期",
											icon: "none"
										});
									}, 400)
								}
							});
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: "none"
							});
						}
					},
					fail: (res) => {
						uni.showToast({
							title: "登录失败",
							icon: "none"
						});
						console.log('set error:' + JSON.stringify(e));
					}
				});
			},
			qrcodeError(err) {
				console.log(err)
				uni.showModal({
					title: '摄像头授权失败',
					content: '摄像头授权失败，请检测当前浏览器是否有摄像头权限。',
					success: () => {
						uni.navigateBack({})
					}
				})
			}
		}
	}
</script>

<style></style>
